using System;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;

namespace System.Data.DBLib
{
	/// <summary>
	/// Summary description for COleDB.
	/// </summary>
	public class CSqlDB : CDBLib
    {
        #region Constructor
        public CSqlDB()
		{
			//
			// TODO: Add constructor logic here
			//
        }
        #endregion

        #region Parameter
        public override DbParameter addParameter(string strFieldName, int nSize, int nType)
        {
            if (nType == 1)
            {
                return ((SqlCommand)m_objCommand).Parameters.Add("@" + strFieldName, getType(nType), nSize);
            }
            else
            {
                return ((SqlCommand)m_objCommand).Parameters.Add("@" + strFieldName, getType(nType));
            }
        }
        #endregion

        #region Function
        public override DbConnection getConnection(string strConnection)
        {
            return new SqlConnection(m_strConnection);
        }

        public override DbCommand getCommand(string strSql)
        {
            return new SqlCommand(strSql, (SqlConnection)m_objConnection);
        }

        public override DbDataAdapter getAdapter(string strSql)
        {
            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = (SqlCommand)getCommand(strSql);

            return da;
        }

        public override DbDataAdapter getAdapter()
        {
            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = (SqlCommand)m_objCommand;

            return da;
        }

        private SqlDbType getType(int nType)
		{
			switch (nType)
			{
				case 0:
					return SqlDbType.Int;
				case 1:
					return SqlDbType.VarChar;
				case 2:
                    return SqlDbType.Decimal;
				case 3:
					return SqlDbType.NVarChar;
				case 4:
					return SqlDbType.DateTime;
				case 5:
					return SqlDbType.BigInt;
				case 6:
					return SqlDbType.Decimal;
                case 7:
                    return SqlDbType.VarBinary;
                case 8:
                    return SqlDbType.Text;
                default:
					return SqlDbType.VarChar;
			}
		}
        #endregion
	}
}